import {TableAttributeBean} from '../bean/TableAttributeBean';
import {Constant} from '../Contant';
import {RecordValueDataFormat} from '../bean/RecordValueDataFormatBean';
import {DataSourceBean} from '../bean/DataSourceBean';
class TableElementBean {
  elementId;
  constructor(isNeedBindPoint = Constant.NEED_TO_BIND_POINT, tableAttribute = new TableAttributeBean(), elementDataList = [],
    dataFormat = new RecordValueDataFormat(), dataSource = new DataSourceBean()) {
    this.tableAttribute = tableAttribute;
    this.elementDataList = elementDataList;
    this.isNeedBindPoint = isNeedBindPoint;
    this.dataFormat = dataFormat;
    this.dataSource = dataSource;
    this.isCustomElement = false;
    this.originLabelName = tableAttribute.labelName;
  }
  get tableAttribute() {
    return this.tableAttribute;
  }
  get elementDataList() {
    return this.elementDataList;
  }
  get isNeedBindPoint() {
    return this.isNeedBindPoint;
  }
  get dataFormat() {
    return this.dataFormat;
  }
  get dataSource() {
    return this.dataSource;
  }
  get isCustomElement() {
    return this.isCustomElement;
  }
  get originLabelName() {
    return this.originLabelName;
  }
  get elementId() {
    return this.elementId;
  }
  set elementId(elementId) {
    this.elementId = elementId;
  }
  set originLabelName(originLabelName) {
    this.originLabelName = originLabelName;
  }
  set isCustomElement(isCustomElement) {
    this.isCustomElement = isCustomElement;
  }
  set dataSource(dataSource) {
    this.dataSource = dataSource;
  }
  set elementDataList(elementDataList) {
    this.elementDataList = elementDataList;
  }
  set tableAttribute(tableAttribute) {
    this.tableAttribute = tableAttribute;
  }
  set dataFormat(dataFormat) {
    this.dataFormat = dataFormat;
  }
  putDataIntoDataList(dataValue) {
    let value = dataValue;
    if (this.dataFormat) {
      value = this.dataFormat.formatData(value);
    }
    this.elementDataList.push(value);
  }
  putDatasIntoDataList(datas) {
    this.elementDataList = [...this.elementDataList, ...datas];
  }
  resetDataList(num, value) {
    if ((this.elementDataList).length > 0 && this.elementDataList[0] === value) {
      return;
    }
    this.elementDataList.splice(0, this.elementDataList.length);
    for (let i = 0; i < num; i++) {
      this.elementDataList.push(value);
    }
  }
}
export {
  TableElementBean
};